home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ccdl150l.zip / IO / UNGETC.C < prev    next >
C/C++ Source or Header  |  1996-07-27  |  553b  |  28 lines

  1. #include <stdio.h>
  2.  
  3. #undef ungetc
  4. int ungetc(int c, FILE *stream)
  5. {
  6.     if (stream->token != FILTOK)
  7.         return EOF;
  8.     if (stream->buffer) {
  9.         if ((stream->flags & _F_IN) && stream->curp != stream->buffer) {
  10.             stream->level++;
  11.             (*--stream->curp) = (char)c;
  12.         }
  13.         else {
  14.             if (fflush(stream))
  15.                 return EOF;
  16.             stream->flags |= _F_IN;
  17.         stream->level = 1;
  18.             stream->curp = stream->buffer+stream->bsize;
  19.             *--stream->curp = (char)c;
  20.         }
  21.     }
  22.     else {
  23.         if (stream->hold)
  24.             return EOF;
  25.         stream->hold = (char)c;
  26.     }
  27.     return c;
  28. }